/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.chl.cid.beans;

import edu.chl.cid.entities.Customer;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author rhodinj
 */
@Stateless
public class LoginEJB {

    @PersistenceContext(unitName="sasanshop_pu")
    private EntityManager em;

    public boolean validateUser (String loginname, String password)
    {
        Query query = em.createNamedQuery("findAllCustomers");
        List<Customer> customers = query.getResultList();

        for (Customer c : customers)
        {
            if (c.getEmail().equals(loginname) && c.getPass().equals(password) )
                return true;
        }

        return false;
    }



}
